<?php session_start();
//Check if logged in. If not, send to login page
if(!isset($_SESSION['loggedIn'])){
	header('Location: StudentLogin.php');
}
//Find all assigments in the class that aren't commented out.
//If they don't exist as folders, make them
$str="../data/Classes/" . $_SESSION['class'] . "/Assignments/";
if(file_exists($str . "assignments.txt")){
	$file=$str . "assignments.txt";
	$fr=fopen($file,'r');
	while (!feof($fr)){
		$str2=fgets($fr);
		$str2=trim($str2);
		if(strcmp(substr($str2,0,1),"#") != 0){
			if(!file_exists($str . $str2) || !is_dir($str . $str2)){
				mkdir($str . $str2);
			}
		}
	}
	fclose($fr);
}
?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta content="en-us" http-equiv="Content-Language" />
<meta content="text/html; charset=utf-8" http-equiv="Content-Type" />
<link href="main.css" rel="stylesheet" type="text/css" />
<title>Assignment</title>
<script type="text/javascript">
function assignChanged(i){
	document.assignmentForm.assign.value=document.assignmentForm.assignmentSelect.options[i].value;
}
</script>
</head>
<body >
&nbsp;
<p>&nbsp; &nbsp;</p>
&nbsp;
	<div id="navigation"><ul>
    <li><a href="logout.php">Logout</a></li>
    <li><a href="ChangePassword.php">Change Password</a></li>
    <li><a href="ViewAssignment.php">View Uploaded Assignments</a></li>
    <!--<li><a href="/main/index.php">Home</a></li>-->
</ul></div>
    <div id="wrapper">
      	<div id="section">
            <div id='sectionHeader'>Assignments</div>
&nbsp;
        <!-- GROUP CONTENT -->
	<a href="ViewAssignment.php">View uploaded Assignments</a>
	</p>
    <form name="assignmentForm" id="assignmentForm" action="upload.php" method="post" enctype="multipart/form-data">
    	<input type="hidden" name="assign" value="" />
    	<select name="assignmentSelect" id="assignmentSelect" onChange="assignChanged(document.assignmentForm.assignmentSelect.selectedIndex);">
    		<?php 
    		//Find all assignments that are uncommented and add them to dropdown box
    		if(file_exists($file)){
    			$fr=fopen($file,'r');
    			while (!feof($fr)){
    				$str2=fgets($fr);
    				$str2=trim($str2);
    				if(strcmp($str2,"") != 0){
    					if(strcmp(substr($str2,0,1),"#") != 0){
    						echo "<option value=\"" . $str2 . "\">" . $str2 . "</option>";
    					}
    				}
    			}
    		}
    		?>
    	</select>
    	<script type="text/javascript">
		assignChanged(0);
		</script>
		<label for="file">File for upload:</label>
    	<input type="file" name="file" id="file" />
    	<br />
    	<p>Message(optional)</p>
		<textarea name="MessageTextArea" cols="60" rows="6"></textarea>
    	<br />
    	<input name="UploadButton" type="submit" value="Upload" />
    </form>
	<!-- END GROUP CONTENT -->
        </div>
    </div>
</body>
</html>